package com.martin.study.others;

public class ThreadLocalTest {
	public static void main(String[] args) {
		Thread threadA = new Thread(new Runnable() {
			@Override
			public void run() {
				for (int i = 0; i<10;i++){
					System.out.println(ThreadLocalHolder.get());
					ThreadLocalHolder.set("threadA"+i);
					try {
						Thread.sleep(1000L);
					} catch (InterruptedException e) {
						throw new RuntimeException(e);
					}
				}
			}
		});
		threadA.setName("threadA");
		Thread threadB = new Thread(new Runnable() {
			@Override
			public void run() {
				for (int i = 0; i<10;i++){
					System.out.println(ThreadLocalHolder.get());
					ThreadLocalHolder.set("threadB"+i);
					try {
						Thread.sleep(1000L);
					} catch (InterruptedException e) {
						throw new RuntimeException(e);
					}
				}
			}
		});
		threadA.setName("threadB");
		threadA.start();
		threadB.start();

	}
}
